namespace BenchmarkWatch.NET
{
    public struct WatchRecord
    {
        public WatchRecord(long totalsMilliseconds, int times = 1)
        {
            TotalsMilliseconds = totalsMilliseconds;
            Times = times;
        }

        /// <summary>
        /// 次数
        /// </summary>
        public int Times { get; set; }

        /// <summary>
        /// 合计耗时(ms)
        /// </summary>
        public long TotalsMilliseconds { get; set; }

        /// <summary>
        /// 平均每次耗时(ms)
        /// </summary>
        public long MillisecondsPer => TotalsMilliseconds / Times;

        public static WatchRecord operator +(WatchRecord a) => a;

        public static WatchRecord operator +(WatchRecord a, long b)
            => new WatchRecord(a.TotalsMilliseconds + b, a.Times + 1);

        public static WatchRecord operator +(long a, WatchRecord b)
            => new WatchRecord(a + b.TotalsMilliseconds, b.Times + 1);

        public static WatchRecord operator +(WatchRecord a, WatchRecord b)
            => new WatchRecord(a.TotalsMilliseconds + b.TotalsMilliseconds, a.Times + b.Times);
    }
}
